import multiprocessing
import time
import os
import random


def download_task(filename):
    print(filename)
    print('启动下载进程，进程号[%d].' % os.getpid())
    print('开始下载%s...' % filename)
    time_to_download = random.randint(5, 10)
    time.sleep(time_to_download)
    print('%s下载完成! 耗费了%d秒' % (filename, time_to_download))


def main():
    start = time.time()
    p1 = multiprocessing.Process(target=download_task, args='https://tb-video.bdstatic.com/tieba-smallvideo-transcode-crf/18_d0de441361814e2821d0e0bebfc3a10d_0.mp4?vt=0&pt=3&ver=&cr=2&cd=0&sid=&ft=2&tbau=2024-02-10_2f01b675f233fd587d1d2c760a491ea2859ffb1962c704c92547cb119052fb4c&ptid=8874719327')
    p1.start()
    p2 = multiprocessing.Process(target=download_task, args='https://tb-video.bdstatic.com/tieba-smallvideo-transcode-crf/11_26f267cbb3b769524722dfefe6dc6dc5_0.mp4?vt=0&pt=3&ver=&cr=2&cd=0&sid=&ft=2&tbau=2024-02-10_01b4082b0fcd52fa1349a11cfebdc31546f66a17da15a0ce9819288e28c2802c&ptid=8841860755')
    p2.start()
    p1.join()
    p2.join()
    end = time.time()
    print('总共耗费了%.2f秒.' % (end - start))


if __name__ == '__main__':
    main()
